#ifndef __DEF_KAKEIBO_H__
#define __DEF_KAKEIBO_H__

#include <wx/wx.h>
#include <wx/spinctrl.h>
#include <wx/splitter.h>
#include <wx/calctrl.h>
#include <wx/listctrl.h>
#include <wx/notebook.h>
#include <wx/treectrl.h>
#include <wx/datectrl.h>
#include <wx/slider.h>
#include <wx/grid.h>
#include <wx/dnd.h>
//#include <wx/wxsqlite3.h>
#include <wx/log.h>
#include "appconstant.h"
#include "dbkakeibo.h"

#include "de_dialog.h"
#include "ex_dialog.h"
#include "ac_dialog.h"
#include "st_dialog.h"
#include "im_dialog.h"
#include "pt_dialog.h"
#include "chartpk.h"
#include "repprt.h"

//#include <stack>
#include <vector>


//pre-define

//define class

class DDFile: public wxFileDropTarget
{
public:
	DDFile(wxWindow *own) { owner = own; }
	virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames);
private:
	wxWindow *owner;
};

class MyFrame: public wxFrame
{
public:
	MyFrame(const wxString &title);
	virtual ~MyFrame(void);
	
	void Open_File(const wxString name = wxEmptyString);
	void Save_File(bool isoverwrite, const wxString &name = wxEmptyString);
	int Close_File(void);
	void CreateRecent(void);
	wxPageSetupDialogData *GetPageSetupData(void) { return pagesetup_data; }
	wxString GetReportTitle(void) { return km_ReportTitle->GetValue(); }
	void SetReportTitle(const wxString &title) { km_ReportTitle->SetValue(title); }
	void GetReportHeaderInfo(bool *enable, bool *useline, wxString header[]);
	void GetReportFooterInfo(bool *enable, bool *useline, wxString footer[]);
	void SetReportHeaderInfo(bool enable, bool useline, wxString header[]);
	void SetReportFooterInfo(bool enable, bool useline, wxString footer[]);
	int GetReportOptions(bool options[]);
	void SetReportOptions(bool options[]);
protected:
	//visible control
	wxMenuBar *km_MenuBar;
		wxMenu *km_file_recent;
	wxToolBar *km_ToolBar;
		wxButton *km_tool_Exit;
		wxChoice *km_tool_Handling;
	wxPanel *allPanel;
	wxSplitterWindow *km_SplitWin;
	wxPanel *mainPanel1;
		wxCalendarCtrl *km_Calender;
		wxSpinCtrl *km_CalenYear;
		wxSpinCtrl *km_CalenMonth;
		wxButton *km_ReturnToday;
		wxButton *km_AddDetail;
		wxButton *km_ModDetail;
		wxButton *km_DelDetail;
		wxButton *km_JumpPast;
		wxButton *km_JumpFuture;
		wxStaticBox *mstbox;
		wxStaticBoxSizer *mstsizer;
		wxButton *km_TurnStackPeriod;
			wxStaticText *km_InfoPeriod;
			wxListBox *km_StackPeriod;
		wxButton *km_TurnFinishPeriod;
			wxButton *km_ClearPeriod;
			wxListBox *km_FinishPeriod;
	wxNotebook *mainPanel2;
		wxPanel *km_DayDetailPanel;
			wxListCtrl *km_DayDetail;
			wxListCtrl *km_DayResult;
		wxPanel *km_WeekDetailPanel;
			wxGrid *km_WeekDetail;
		wxPanel *km_MonthDetailPanel;
			wxGrid *km_MonthDetail;
		wxPanel *km_SearchPanel;
			wxSplitterWindow *km_SearchSplit;
			wxPanel *km_SearchCtrl;
				wxButton *km_SerUseIO;
				wxChoice *km_SerIO;
				wxButton *km_SerUseDate;
				wxDatePickerCtrl *km_SerDate;
				wxChoice *km_SerDateCond;
				wxButton *km_SerUseHandling;
				wxChoice *km_SerHandling;
				wxButton *km_SerUseExpense;
				wxBitmapComboBox *km_SerExpense;
				wxCheckBox *km_SerUserItems;
				wxBitmapComboBox *km_SerItems;
				wxButton *km_SerUseIncome;
				wxSpinCtrl *km_SerIncome;
				wxChoice *km_SerIncomeCond;
				wxListBox *km_SerCondList;
				wxButton *km_SerAdd;
				wxButton *km_SerDel;
				wxButton *km_SerExecute;
				wxChoice *km_SerAndCond;
				wxButton *km_SerClear;
			wxPanel *km_SearchMain;
				wxListCtrl *km_SearchDetail;
			wxPanel *km_ChartPanel;
				wxPanel *km_ChartCtrl;
					wxChoice *km_ChartSource;
					wxButton *km_ChartOn;
				ChartPicker *km_ChartMain;
			wxPanel *km_ReportPanel;
				wxChoice *km_ReportSource;
				wxCheckBox *km_ReportEnableHeader;
				wxCheckBox *km_ReportLineHeader;
				wxTextCtrl *km_ReportHeader[3];
				wxCheckBox *km_ReportEnableFooter;
				wxCheckBox *km_ReportLineFooter;
				wxTextCtrl *km_ReportFooter[3];
				wxTextCtrl *km_ReportTitle;
				wxCheckListBox *km_ReportOptions;
				wxButton *km_ReportPublish;

	
	wxStatusBar *km_StatusBar;
	
	DetailEditor *de_dialog;
	ExpenseDialog *ed_dialog;
	AccountDialog *ac_dialog;
	SettingDialog *st_dialog;
	ImportDialog *im_dialog;
	wxLogWindow *log_dialog;
	ReportDialog *rep_dialog;
	PeriodicalTranDialog *pt_dialog;
	void fileMenu_New_clicked(wxCommandEvent &event);
	void fileMenu_Open_clicked(wxCommandEvent &event);
	void fileMenu_Save_clicked(wxCommandEvent &event);
	void fileMenu_Close_clicked(wxCommandEvent &event);
	void fileMenu_Recent_clicked(wxCommandEvent &event);
	void fileMenu_Exit_clicked(wxCommandEvent &event);
	void fileMenu_SetPrinter_clicked(wxCommandEvent &event);
	void editMenu_Cut_clicked(wxCommandEvent &event);
	void editMenu_Copy_clicked(wxCommandEvent &event);
	void editMenu_Paste_clicked(wxCommandEvent &event);
	void editMenu_AddFavorite_clicked(wxCommandEvent &event);
	void editMenu_DelFavorite_clicked(wxCommandEvent &event);
	void editMenu_GoFavorite_clicked(wxCommandEvent &event);
	void toolMenu_SetGeneral_clicked(wxCommandEvent &event);
	void toolMenu_SetPeriodical_clicked(wxCommandEvent &event);
	void toolMenu_SetExpense_clicked(wxCommandEvent &event);
	void toolMenu_SetAccount_clicked(wxCommandEvent &event);
	void toolMenu_Import_clicked(wxCommandEvent &event);
	void toolMenu_Log_clicked(wxCommandEvent &event);
	void toolMenu_DelLog_clicked(wxCommandEvent &event);
	void toolMenu_Report_clicked(wxCommandEvent &event);
	void viewMenu_Tabs_clicked(wxCommandEvent &event);
	void helpMenu_Contents_clicked(wxCommandEvent &event);
	void helpMenu_About_clicked(wxCommandEvent &event);
	void km_ReturnToday_clicked(wxCommandEvent &event);
	
	void km_AddDetail_clicked(wxCommandEvent &event);
	void km_ModDetail_clicked(wxCommandEvent &event);
	void km_DelDetail_clicked(wxCommandEvent &event);
	void km_JumpBtn_clicked(wxCommandEvent &event);

	void km_CalenYM_spined(wxSpinEvent &event);
	void km_Calender_changed(wxCalendarEvent &event);
	void km_DayDetail_selected(wxListEvent &event);
	void km_DayDetail_deselected(wxListEvent &event);
	void km_DayDetail_activated(wxListEvent &event);
	void mainPanel2_changed(wxNotebookEvent &event);
	void km_tool_Handling_selected(wxCommandEvent &event);
	void MyFrame_close(wxCloseEvent &event);
	void km_StackPeriod_dblclicked(wxCommandEvent &event);
	void km_SerIO_changed(wxCommandEvent &event);
	void km_SerUseExpense_changed(wxCommandEvent &event);
	void km_SerAdd_clicked(wxCommandEvent &event);
	void km_SerDel_clicked(wxCommandEvent &event);
	void km_SerExecute_clicked(wxCommandEvent &event);
	void km_SerClear_clicked(wxCommandEvent &event);
	void km_ChartOn_clicked(wxCommandEvent &event);
	void km_ReportPublish_clicked(wxCommandEvent &event);
	void km_ClearPeriod_clicked(wxCommandEvent &event);
	void km_Turn_Period_clicked(wxCommandEvent &event);
	void km_SearchDetail_colclicked(wxListEvent &event);
	//invisible control and class
private:
	wxPanel *setup_daydetailpage(wxNotebook *book);
	wxPanel *setup_weekdetailpage(wxNotebook *book);
	wxPanel *setup_monthdetailpage(wxNotebook *book);
	wxPanel *setup_searchpage(wxNotebook *book);
	wxPanel *setup_chartpage(wxNotebook *book);
	wxPanel *setup_reportpage(wxNotebook *book);
	void InsertRow(wxListCtrl *ctrl, wxString list[], size_t size, int imgid[], size_t imgsize);
	void ChangeRow(wxListCtrl *ctrl, int index, wxString list[], size_t size, int imgid[], size_t imgsize);
	void DeleteRow(wxListCtrl *ctrl, int index);
	void UpdateDB(void);
	void UpdateFuture(DB_total &tdb);
	void ChangePage(const wxDateTime &date, int handling);
	void ChangeRowTotal(DB_total db, int budget = 0, int budgetdiff = 0);
	void GenerateExpenseInDetail(bool onname, bool ondata, int handle, int showtype = -1);
	void SetValueInDetail(wxGrid **grid, int gridcols, wxSQLite3ResultSet rset, DB_total &totdb);
	void UpdateControl(void);
	void InsertPresetData(void);
	void UpdateLinkedBudget(DB_day &db);
	bool CheckBudgetDate(wxDateTime date, int handling, DB_reserved &db, int *result);
	int CheckSincePeriodical(const wxDateTime &date);
	bool CheckAlreadyPeriodical(DB_day &db, wxString flag);
	void SetExpense(InoutType io);
	void SetItems(int expenseId);
	wxString GenerateLinkId(const wxDateTime &date, int io, int handling, int id);
	void turnControlState(bool flag);
	void SetKakeiboTitle(wxFileName &fname, const wxString &title);
	void SetFavoriteMenu(DB_periodical &newrow);
	void RotateRecent(const wxString &newfile);
	wxString EncryptKakeibo(const wxString &file, int key1, int key2, int key3, int key4, int key5);
	wxString DecryptKakeibo(const wxString &file);
private:
	DECLARE_EVENT_TABLE()
	//wxLocale locale;
	std::vector<DB_day> dbbudget;
	std::vector<DB_day> clip_dbbudget;
	std::vector<int> dbaccountId;
	std::vector<int> dbexpenseId;
	std::vector<int> dbitemsId;
	wxArrayString searchstrs;
	std::vector<DB_periodical> stock_dbperiod;
	DBL_periodical db_menufavorites;
	DB_total dbtotal;
	std::vector<DB_day> dbsearch;
	int listselect;
	int curhandling;
	wxPageSetupDialogData pageInfo;
	//testcode: print
	wxPrintData *print_data;
	wxPageSetupDialogData *pagesetup_data;
	//testcode: print
	bool show_stackperiod;
	bool show_finishperiod;
	wxString searchSQL;
};


enum {
	kakeibo_new = 10,
	kakeibo_open,
	kakeibo_save,
	kakeibo_saveas,
	kakeibo_close,
	kakeibo_exit,

	kakeibo_adddetail,
	kakeibo_moddetail,
	kakeibo_cut,
	kakeibo_copy,
	kakeibo_paste,
	kakeibo_deldetail,
	kakeibo_favorite,
	kakeibo_addfav,
	kakeibo_delfav,

	kakeibo_viewday,
	kakeibo_viewweek,
	kakeibo_viewmonth,
	kakeibo_viewsearch,
	kakeibo_viewreport,

	kakeibo_setgeneral,
	kakeibo_setperiodicaltran,
	kakeibo_setexpense,
	kakeibo_setaccount,
	kakeibo_import,
	kakeibo_calllog,
	kakeibo_dellog,

	kakeibo_contents,
	kakeibo_about,
	kakeibo_calyear,
	kakeibo_calmonth,
	kakeibo_returntoday,
	kakeibo_calendar,
	kakeibo_daydetail,
	kakeibo_weekdetail,
	kakeibo_monthdetail,
	kakeibo_main2,
	kakeibo_toolhandling,
	kakeibo_stockbudget,
	kakeibo_serio,
	kakeibo_serexpense,
	kakeibo_seraddio,
	kakeibo_seradddate,
	kakeibo_seraddaccount,
	kakeibo_seraddexpense,
	kakeibo_seraddamount,
	kakeibo_serdel,
	kakeibo_serexe,
	kakeibo_serclear,
	kakeibo_serdetail,
	kakeibo_charton,
	kakeibo_setprinter,
	kakeibo_reportpublish,
	kakeibo_callreport,
	kakeibo_jumppast,
	kakeibo_jumpfuture,
	kakeibo_clearperiod,
	kakeibo_turnstackperiod,
	kakeibo_turnfinishperiod,
	kakeibo_enableheader,
	kakeibo_enablefooter,

	kakeibo_favzero = 100,
	kakeibo_fav01 = 101,
	kakeibo_fav02,
	kakeibo_fav03,
	kakeibo_fav04,
	kakeibo_fav05,
	kakeibo_fav06,
	kakeibo_fav07,
	kakeibo_fav08,
	kakeibo_fav09,
	kakeibo_fav10,
	kakeibo_fav11,
	kakeibo_fav12,
	kakeibo_fav13,
	kakeibo_fav14,
	kakeibo_fav15,
	kakeibo_fav16,
	kakeibo_fav17,
	kakeibo_fav18,
	kakeibo_fav19,
	kakeibo_fav20,

	kakeibo_recentzero = 150,
	kakeibo_recent01 = 151,
	kakeibo_recent02,
	kakeibo_recent03,
	kakeibo_recent04,
	kakeibo_recent05
};

#endif
